package cn.huang.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import cn.huang.entity.Result;
import cn.huang.pojo.Address;
import cn.huang.service.AddressService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mobileAddress")
public class AddressController {
    @Reference
    private AddressService addressService;
    //手机端查询所有地址信息
    @RequestMapping("/findAll4Mobile")
    public Result findAll4Mobile() {
        try {
            List<Address> addressList = addressService.findAll();

            List<Map> jsonMap = new ArrayList<Map>();
            for (Address address : addressList) {
                Map<String,Object> map = new HashMap<String, Object>();
                map.put("id",address.getId());
                map.put("text",address.getAddress());
                jsonMap.add(map);
            }
            return new Result(true,"查询地址列表成功！",jsonMap);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询地址列表失败！");
        }
    }
}
